package com.YxyBackMange.Controller.web;

import com.YxyBackMange.Dto.QueryInfo;
import com.YxyBackMange.Entity.Sys.SysUser;
import com.YxyBackMange.Entity.Ware.WareAppointment;
import com.YxyBackMange.Entity.Ware.WareGoodsInfo;
import com.YxyBackMange.Mapper.web.WebAppointmentMapper;
import com.YxyBackMange.Service.web.WebAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @outhor 路♥克
 * 2017-12-15 21:04
 */
@Controller
@RequestMapping("/Appointment")
public class WebAppointmentController {

    @Autowired
    private WebAppointmentMapper webAppointmentMapper;

    @Autowired
    private WebAppointmentService webAppointmentService;
    @RequestMapping("/selectAppointmentByUserId")
    public String selectAppointmentByUserId(HttpSession session, ModelMap modelMap){
        SysUser user = (SysUser)session.getAttribute("user");
        if(user!=null){
            Map<String,String> map = new HashMap<String, String>();
            map.put("user_id",user.getId().toString());
            QueryInfo queryInfo = new QueryInfo();
            queryInfo.setMap(map);
            List<WareAppointment> wareAppointmentList = webAppointmentMapper.selectQueryInfo(queryInfo);
            modelMap.put("wareAppointmentList",wareAppointmentList);
        }
        return "/web/subscribe.jsp";
    }
    @RequestMapping("/deleteAppointmentById")
    public String deleteAppointmentById(Integer id){
        webAppointmentService.delete(new WareAppointment(id));
        return "/Appointment/selectAppointmentByUserId";
    }
    @RequestMapping(value = "/insertAppointment",method = RequestMethod.GET)
    public @ResponseBody String deleteAppointment(Integer GoodsId, HttpSession session){
        SysUser user = (SysUser)session.getAttribute("user");
        WareAppointment appointment = new WareAppointment();
        appointment.setUserId(user.getId());
        appointment.setGoodsId(GoodsId);
        appointment.setContactsName(user.getUsername());
        appointment.setContactsPhone(user.getPhone());
        WareAppointment appointment1 = webAppointmentService.insertService(appointment);
        if (appointment1!=null) {
            return "success";
        }
        return "error";
    }
}
